package com.gduf.lsm.controller;

import com.gduf.lsm.common.Result;
import com.gduf.lsm.entity.ApplyMental;
import com.gduf.lsm.pojo.dto.ApplyServeStatusDTO;
import com.gduf.lsm.pojo.vo.ApplyMaintainShowVO;
import com.gduf.lsm.pojo.vo.ApplyMentalShowVO;
import com.gduf.lsm.pojo.vo.EvaluationVO;
import com.gduf.lsm.service.ApplyMentalService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 维修服务预约前端操作接口
 **/
@RestController
@RequestMapping("/applyMental")

public class ApplyMentalController {

    @Resource
    private ApplyMentalService applyMentalService;

    /**
     * 新增
     * @param applyMental
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ApplyMental applyMental) {
        //System.out.println("*****applyMental*****"+applyMental);
        applyMentalService.add(applyMental);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        applyMentalService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        applyMentalService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     * @param applyMental
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody ApplyMental applyMental) {
        applyMentalService.updateById(applyMental);
        return Result.success();
    }

    /**
     * 已投诉，已处理
     * @param applyServeStatusDTO
     * @return
     */
    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody ApplyServeStatusDTO applyServeStatusDTO){
        applyMentalService.updateStatus(applyServeStatusDTO);
        return Result.success();
    }

    /**
     * 管理员处理已处理状态，添加医生与热线，状态修改为已完成
     * @param applyServeStatusDTO
     * @return
     */
    @PutMapping("/updateHandle")
    public Result updateHandle(@RequestBody ApplyServeStatusDTO applyServeStatusDTO){
        applyMentalService.updateHandle(applyServeStatusDTO);
        return Result.success();
    }

    /**
     * 用户已评价
     * @param applyServeStatusDTO
     * @return
     */
    @PutMapping("/updateEvaluation")
    public Result updateEvaluation(@RequestBody ApplyServeStatusDTO applyServeStatusDTO){
        applyMentalService.updateEvaluation(applyServeStatusDTO);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ApplyMental applyMental = applyMentalService.selectById(id);
        return Result.success(applyMental);
    }

    /**
     * 查询所有
     * @param applyMental
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(ApplyMental applyMental ) {
        List<ApplyMental> list = applyMentalService.selectAll(applyMental);
        return Result.success(list);
    }

    /**
     * 用户端查询已预约的心理健康服务
     * @param userId
     * @return
     */
    @GetMapping("/selectByUserId/{userId}")
    public Result selectByUserId(@PathVariable Integer userId){
        List<ApplyMentalShowVO> list=applyMentalService.selectByUserId(userId);
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param applyMental
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(ApplyMental applyMental,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ApplyMentalShowVO> page = applyMentalService.selectPage(applyMental, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 获取维修服务所有评价分数及内容
     * @return
     */
    @GetMapping("/getEvaluations")
    public Result getEvaluations(){
        List<EvaluationVO> list=applyMentalService.getEvaluations();
        return Result.success(list);
    }
}